'''
Created on Nov 28, 2013

@author: devuser
'''

from NewsServer import cnx

class Comment(object):
    
    '''
    This class will get a comment from the database
    '''
    def __init__(self, article_input, order_by, amount, *args):
        #if there are extra arguments, specify the range for the comments
        first, last = args

        cursor = cnx.cursor()
        #need to insert procedure
        if (amount== "all"):
            cursor.callproc("get_article_comments_all", (article_input, order_by,))
        else:
            cursor.callproc("get_article_comments_range", (article_input, first, last, order_by,))
        result = cursor.fetchall()
        cursor.close()
        
        #need to unpack stored procedure
        try:
            self.comment_id, self.user_id, self.article_id, self.comment_text, self.create_time = result
        except: pass